package com.mes.device.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.mes.common.core.utils.poi.ExcelUtil;
import com.mes.common.core.web.controller.BaseController;
import com.mes.common.core.web.domain.AjaxResult;
import com.mes.common.core.web.page.TableDataInfo;
import com.mes.common.log.annotation.Log;
import com.mes.common.log.enums.BusinessType;
import com.mes.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mes.device.domain.DeviceRepair;
import com.mes.device.service.IDeviceRepairService;

/**
 * 设备报修Controller
 * 
 * @author itflash
 * @date 2025-02-27
 */
@RestController
@RequestMapping("/device/repair")
public class DeviceRepairController extends BaseController
{
    @Autowired
    private IDeviceRepairService deviceRepairService;

    /**
     * 查询设备报修列表
     */
    @RequiresPermissions("device:repair:list")
    @GetMapping("/list")
    public TableDataInfo list(DeviceRepair deviceRepair)
    {
        startPage();
        List<DeviceRepair> list = deviceRepairService.selectDeviceRepairList(deviceRepair);
        return getDataTable(list);
    }

    /**
     * 导出设备报修列表
     */
    @RequiresPermissions("device:repair:export")
    @Log(title = "设备报修", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceRepair deviceRepair)
    {
        List<DeviceRepair> list = deviceRepairService.selectDeviceRepairList(deviceRepair);
        ExcelUtil<DeviceRepair> util = new ExcelUtil<DeviceRepair>(DeviceRepair.class);
        util.exportExcel(response, list, "设备报修数据");
    }

    /**
     * 获取设备报修详细信息
     */
    @RequiresPermissions("device:repair:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deviceRepairService.selectDeviceRepairById(id));
    }

    /**
     * 新增设备报修
     */
    @RequiresPermissions("device:repair:add")
    @Log(title = "设备报修", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceRepair deviceRepair)
    {
        return toAjax(deviceRepairService.insertDeviceRepair(deviceRepair));
    }

    /**
     * 修改设备报修
     */
    @RequiresPermissions("device:repair:edit")
    @Log(title = "设备报修", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceRepair deviceRepair)
    {
        return toAjax(deviceRepairService.updateDeviceRepair(deviceRepair));
    }

    /**
     * 删除设备报修
     */
    @RequiresPermissions("device:repair:remove")
    @Log(title = "设备报修", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deviceRepairService.deleteDeviceRepairByIds(ids));
    }
}
